#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi

ods_product_all_log="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_logs/ods_product_all_log.csv'
    INTO TABLE jtp_goods_warehouse.ods_product_all_log PARTITION (dt = '${data_date}');
"

ods_product="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_product/${data_date}'
    INTO TABLE jtp_goods_warehouse.ods_product PARTITION (dt = '${data_date}');
"

ods_sku="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_sku/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_sku PARTITION (dt = '${data_date}');
"

ods_category="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_category/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_category PARTITION (dt = '${data_date}');
"

ods_brand="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_brand/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_brand PARTITION (dt = '${data_date}');
"

ods_review="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_review/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_review PARTITION (dt = '${data_date}');
"

ods_user_profile="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_user_profile/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_user_profile PARTITION (dt = '${data_date}');
"

ods_content="
LOAD DATA INPATH 'hdfs://node101:8020/warehouse/app_ads/ads/ods_content/${data_date}'
    OVERWRITE INTO TABLE jtp_goods_warehouse.ods_content PARTITION (dt = '${data_date}');
"


/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e  \
"${ods_product_all_log}${ods_product}${ods_sku}${ods_category}
${ods_brand}${ods_review}${ods_user_profile}${ods_content}"